<script setup lang="ts">
// #ifdef MP
import { onAddToFavorites, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
import { wxCollect, wxShare } from '@/libs/share'

onShareAppMessage(wxShare(true))
onShareTimeline(wxShare(false))
onAddToFavorites(wxCollect())
// #endif

import { onUnmounted } from 'vue'

import { imagePath } from '@/libs/file-utils'
import { poster } from './data'

const btn_bg = imagePath('community/friend/poster/btn.png')

const share = () => {
  if (!poster.value) return

  // #ifdef MP-WEIXIN
  uni.showShareImageMenu({
    path: poster.value,
    // @ts-ignore
    entrancePath: '/pages/index/index',
  })
  // #endif
}

onUnmounted(() => poster.value = undefined)
</script>

<template>
  <PageWrapper
    name="community-friend-report-poster"
    :showTopBar="false"
  >
    <image
      v-if="poster"
      class="poster"
      :src="poster"
      mode="widthFix"
      show-menu-by-longpress
    />

    <div
      class="btn"
      :style="{ backgroundImage: btn_bg }"
      @click="share"
    >长按保存图片</div>
  </PageWrapper>
</template>

<style lang="less" scoped>
.poster {
  width: 100%;
}

.btn {
  position: fixed;
  bottom: 100rpx;
  left: 50%;
  transform: translateX(-50%);

  width: 589rpx;
  height: 115rpx;

  color: #61301A;
  font-size: 40rpx;
  line-height: 100rpx;
  text-align: center;

  pointer-events: none;
}
</style>